package com.sky.mapper;

import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单表
     * @param orders
     */
    public void addOrder(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据条件获取指定的支付超时的订单集合
     * @param status
     * @param time 当前时间减去15分钟，过去的15分钟
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    public List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime time);
}
